package com.youmans.dfsservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youmans.common_utils.handler.JwtUtils;
import com.youmans.dfsservice.entity.YoumansPicture;
import com.youmans.dfsservice.mapper.YoumansPictureMapper;
import com.youmans.dfsservice.service.YoumansPictureService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 图片表 服务实现类
 * </p>
 *
 * @author youmans
 * @since 2022-10-16
 */
@Service
@Primary
public class YoumansPictureServiceImpl extends ServiceImpl<YoumansPictureMapper, YoumansPicture> implements YoumansPictureService {

    @Autowired
    private YoumansPictureService youmansPictureService ;
    @Override
    public List<YoumansPicture> findAll() {
        return baseMapper.selectList(null);
    }

    @Override
    public List<YoumansPicture> findAllByUserId(HttpServletRequest request) {
        String id = JwtUtils.getMemberIdByJwtToken(request);
        LambdaQueryWrapper<YoumansPicture> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(YoumansPicture::getUserId,id);
        List<YoumansPicture> list = youmansPictureService.list(queryWrapper);
        return list ;
    }

    @Override
    public IPage<YoumansPicture> selectDelPic(@RequestParam String begin, @RequestParam String userId) {
         List<YoumansPicture> list = baseMapper.selectDelPic(begin,userId);
        System.out.println(list);
        Page page = new Page();
        page.setRecords(list) ;
        page.setTotal(list.size());
        return  page;
    }
//恢复删除的数据
    @Override
    public void batchDelBack(List<String> idList) {
        baseMapper.batchDelByIds(idList);
    }
}
